/*XuTUFStA0CzM1pM23a79ZthbeI8KIXhuStO+k7XBFkg=*/
//@Author: lijun 
// export function handleLoad(refcode, code,script) {
// 	let Item = window[refcode].default;
// 	let that = this;
// 	that.setState({
// 		[code]: Item
// 	})
// 	if(!code){
// 		script.removeEventListener('load', that.handleLoad);
// 	}
// }

/* refcode */
export default function createScript(src, code) {
	var that = this,
		scripts = Array.from(document.getElementsByTagName('script')),
		s = src.split('/'),
		flag,
		refKey;
	var script;
	refKey = s.slice(s.length - 5).join('/');
	refKey = refKey.substring(0, refKey.length - 3);
	flag = scripts.find((e) => {
		return e.src.includes(refKey);
	});
	let handleLoad=(refcode, code) =>{
		let Item = window[refcode].default;
		let that = this;
		that.setState({
			[code]: Item
		})
		if(!code){
			script.removeEventListener('load', that.handleLoad);
		}
	}
	that.handleLoad=handleLoad.bind(that, refKey,code,script);
	if (window[refKey]) {
		// 已经加载过script标签
		handleLoad.call(that, refKey, code);
	} else {
		if (flag) {
			script = flag;
		} else {
			script = document.createElement('script');
			script.src = '../../../../' + src;
			script.type = 'text/javascript';
			document.body.appendChild(script);
		}
		script.addEventListener('load', that.handleLoad);
		// script.onload = script.onload || handleLoad.bind(that, refKey);
	}
}
/*XuTUFStA0CzM1pM23a79ZthbeI8KIXhuStO+k7XBFkg=*/